#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N=1e7+1;
int prime[N];
int v[N];
int m=0;
void get_prime(int n)
{
	
	for (int i = 2; i<=n; i++) {
	if (v[i] == 0) { 
		v[i] = i;
		prime[++m] = i;
	}
	for (int j = 1; j <= m; j++) {
		if (prime[j] > v[i] || prime[j] > n/i) break;
		v[i*prime[j]] = prime[j];
	}
}
}

int main()
{
	get_prime(1e7);
	int t;
	cin>>t;
	while(t--)
	{
		unordered_map<int,int> a;
		int n;
		cin>>n;
		int ans=0;
		for(int i=0;i<n;i++)
		{
			ll num=0;
			cin>>num;
			if(v[num]==num) a[num]++;
			else
			{
				while( num>1 && num%v[num]==0)
				{
				    a[v[num]]++;
				    num/=v[num];
				}
			}
		}
		int cnt=0;
		for(auto &[x,y]:a)
		{
		  //  cout<<x<<' '<<y<<endl;
			if(y>=2)
			{
				ans=ans+y/2;
				y%=2;
			}
			cnt+=y;
		}
/*		cout<<cnt<<endl;
		cout<<ans<<endl;*/
		cout<<ans+cnt/3<<endl;
	}

	return 0;
}

